<template>
	<div id="login">
		<el-card class="box-card">
			<div class="card-name">
				<p>权限管理系统</p>
			</div>
			<el-form :label-position="labelPosition" :rules="rules" ref="formLabelAlign" label-width="80px" :model="formLabelAlign">
				<el-form-item label="名称" prop="LoginName">
					<el-input v-model="formLabelAlign.LoginName"></el-input>
				</el-form-item>
				<el-form-item label="密码" prop="Password">
					<el-input type="password" v-model="formLabelAlign.Password" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="submitForm('formLabelAlign')">提交</el-button>
					<el-button v-on:click="resetForm()">重置</el-button>
				</el-form-item>
			</el-form>
		</el-card>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				labelPosition: 'right',
				formLabelAlign: {
					LoginName: '',
					Password: ''
				},
				rules: {
					LoginName: [{
							required: true,
							message: '请输入登录名称',
							trigger: 'blur'
						},
						{
							min: 2,
							max: 6,
							message: '长度在 2 到 6 个字符',
							trigger: 'blur'
						}
					],
					Password: [{
							required: true,
							message: '请输入密码',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 6,
							message: '长度在 3 到 6 个字符',
							trigger: 'blur'
						}
					]
				}
			}
		},
		methods: {
			resetForm() {
				this.$refs.formLabelAlign.resetFields();
			},
			submitForm() {
				let _this = this;
				this.$axios.post("/api/api/Login/DelLogin", {
					LoginName:_this.formLabelAlign.LoginName,
					Password:_this.formLabelAlign.Password,
				}).then(function(res) {
					if(res.data.code==0){
						this.$message.success("登陆成功");
						window.sessionStorage.setItem('token', res.data.token);
						window.sessionStorage.setItem('Id', res.data.Id);
						//window.sessionStorage.setItem('RoleName', JSON.stringify(res.data.RoleName));
						window.localStorage.setItem('RoleName', JSON.stringify(res.data.RoleName))
						this.$router.push("/home");
						console.log(res.data.RoleName);
					}else if(res.data.code==-1){
						this.$message.error(res.data.msg);
					}else{
						this.$message.error(res.data.msg);
					}
				}.bind(this)).catch(function(err) {
					console.log(err);
				})
			}
		},
		created() {
			this.submitForm();
		},
		mounted() {}
	}
</script>

<style>
	.box-card {
		width: 480px;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
	}

	.card-name {
		background-image: linear-gradient(239deg, #3A6FF3 0%, #50C7FB 100%);
		color: #ffffff;
		margin-bottom: 20px;
		font-size: 24px;
		display: flex;
		justify-content: center;
	}
</style>
